home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FADER / FADE_COD.C < prev    next >
Text File  |  1991-03-01  |  3KB  |  123 lines

  1. /********************************
  2. *
  3. *    Fade In!  v. 1.0
  4. *        by Mark Frohnmayer
  5. *
  6. *    This is some code that demonstrates fading. (as per Hypercard dissolve)
  7. *    Feel free to use this code in any program of your own - it is public
  8. *    domain.  If you have any comments or suggestions, code for other fade
  9. *    algorithms or bug reports, send them to me at "Mark Frohn" on AOL or
  10. *    snail mail me at:
  11. *
  12. *        Mark Frohnmayer
  13. *        2875 Baker Blvd.
  14. *        Eugene, OR  97403
  15. *
  16. ********************************/    
  17. GrafPort    offScreen;
  18. GrafPtr        oldPort;
  19. BitMap        offMap[3];
  20. Rect        copyRect, bitRect;
  21. Handle        fadePats;
  22. int            byteWidth;
  23. extern    WindowPtr MyWindow;
  24.  
  25. InitPicts()
  26. {
  27.     PicHandle thePic;
  28.     int i;
  29.     fadePats = GetResource('PAT#', 130);
  30.     
  31.     byteWidth = 44;
  32.     
  33.     SetRect(©Rect, 0, 0, 348, 211);
  34.     SetRect(&bitRect, 0, 0, 352, 211);
  35.  
  36.     for(i = 0; i < 3; i++) {
  37.         offMap[i].baseAddr = NewPtr((long) (byteWidth * bitRect.bottom));
  38.             if(!offMap[i].baseAddr) ExitToShell();
  39.         offMap[i].rowBytes = byteWidth;
  40.         offMap[i].bounds = bitRect;
  41.     }
  42.  
  43.     GetPort(&oldPort);
  44.     OpenPort(&offScreen);
  45.     
  46.     offScreen.portRect = bitRect;
  47.     offScreen.portBits.bounds = bitRect;
  48.     offScreen.portBits.rowBytes = byteWidth;
  49.     offScreen.portBits.baseAddr = NewPtr(byteWidth * bitRect.bottom);
  50.         if(!offScreen.portBits.baseAddr) ExitToShell();
  51.     
  52.     thePic = GetPicture(128);
  53.     EraseRect(&bitRect);
  54.     DrawPicture(thePic, ©Rect);
  55.  
  56.     CopyBits(&offScreen.portBits, &offMap[0], ©Rect, 
  57.         ©Rect, srcCopy, 0L);
  58.         
  59.     for(i = 32; i >= 0; i--) {
  60.         long curTicks;
  61.         curTicks = TickCount();
  62.         do {} while(curTicks + 2 > TickCount());
  63.         SetFadePat(i);
  64.         PaintRect(©Rect);
  65.         CopyBits(&offMap[0], &offScreen.portBits, ©Rect, 
  66.             ©Rect, notSrcBic, 0L);
  67.         CopyBits(&offScreen.portBits, &MyWindow->portBits, ©Rect, 
  68.             ©Rect, srcCopy, 0L);
  69.     }
  70.     do{} while(!Button());
  71.  
  72.     for(i = 32; i >= 0; i--) {
  73.         long curTicks;
  74.         curTicks = TickCount();
  75.         do {} while(curTicks + 2 > TickCount());
  76.         SetFadePat(i);
  77.         PaintRect(©Rect);
  78.         CopyBits(&offMap[0], &offScreen.portBits, ©Rect, 
  79.             ©Rect, srcOr, 0L);
  80.         CopyBits(&offScreen.portBits, &MyWindow->portBits, ©Rect, 
  81.             ©Rect, srcCopy, 0L);
  82.     }
  83.  
  84.     thePic = GetPicture(129);
  85.     EraseRect(&bitRect);
  86.     DrawPicture(thePic, ©Rect);
  87.     CopyBits(&offScreen.portBits, &offMap[0], ©Rect, 
  88.         ©Rect, srcCopy, 0L);
  89.  
  90.     for(i = 0; i < 33; i++) {
  91.         long curTicks;
  92.         curTicks = TickCount();
  93.         do {} while(curTicks + 2 > TickCount());
  94.         SetFadePat(i);
  95.         PaintRect(©Rect);
  96.         CopyBits(&offMap[0], &offScreen.portBits, ©Rect, 
  97.             ©Rect, srcOr, 0L);
  98.         CopyBits(&offScreen.portBits, &MyWindow->portBits, ©Rect, 
  99.             ©Rect, srcCopy, 0L);
  100.     }
  101.  
  102.     
  103.     
  104.     ReleaseResource(thePic);
  105.     SetPort(oldPort);
  106. }
  107.  
  108. UpdatePict()
  109. {
  110.     PicHandle thePic;
  111.     thePic = GetPicture(129);
  112.     DrawPicture(thePic, ©Rect);
  113.     ReleaseResource(thePic);
  114. }
  115.  
  116. SetFadePat(int patNum)
  117. {
  118.     GrafPtr oopt;
  119.     GetPort(&oopt);
  120.     SetPort(&offScreen);
  121.     PenPat(*fadePats + 8 * patNum + 2);
  122.     SetPort(oopt);
  123. }